using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SQLDAL;
using System.Data.SqlClient;


/// <summary>
/// This FoodBll include all function according to food
/// Written by: PHUONG
/// Date: 7/5/2009
/// </summary>
public partial class GUI_Webpage_FoodDetails : System.Web.UI.Page
{
    #region Fields
    FoodBll foodBll = new FoodBll();
    FoodInfo foodInfo = new FoodInfo();
    TypeOfFoodBll typeOfFoodBll = new TypeOfFoodBll();
    TypeOfFoodInfo typeFoodInfo = new TypeOfFoodInfo();
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        LoadFoodToDetailsView();
        if (!IsPostBack)
        {
            typeOfFoodBll.LoadTypeOfFood(drpTypeFood);
        }
    }

    protected void drpTypeFood_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            dtView.Visible = false;
        }
        //check type of food select
        if (drpTypeFood.SelectedValue == "---Select Type---")
        {
            drpFood.SelectedIndex = 0;
        }
        else
        {
            typeFoodInfo.TypeID = int.Parse(drpTypeFood.SelectedValue);
            foodBll.LoadFoodByType(drpFood, typeFoodInfo);
        }
    }

    protected void drpFood_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (drpFood.SelectedValue.ToString() == "--Select food--")
        {
            dtView.EmptyDataText = "You need select any food";
        }
        foodInfo.FoodID = drpFood.SelectedValue.ToString();
        dtView.Visible = true;
        LoadToDetailsViewWhenSelectFood(foodInfo);
    }


    /// <summary>
    /// Load data to details view when choose a food from Dropdownlist ddlFood
    /// By: PHUONG
    /// Date: 8/5/2009
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>

    #region Load data from the home page to this page to view details any food
    public void LoadFoodToDetailsView()
    {
        string foodID = Request.QueryString.Get("foodID");
        if (foodID != "" && foodID != null)
        {
            foodInfo.FoodID = foodID;
            SqlDataReader reader = foodBll.ListDetailsFood(foodInfo);
            dtView.DataSource = reader;
            dtView.DataBind();
        }
        else
            Response.Redirect("Home.aspx");
    }
    #endregion

    #region Load data to details view when choose a food from Dropdownlist ddlFood
    public void LoadToDetailsViewWhenSelectFood(FoodInfo foodInfo)
    {
        SqlDataReader reader = foodBll.ListDetailsFood(foodInfo);
        dtView.DataSource = reader;
        dtView.DataBind();
    }
    #endregion
}
